package com.unirio.pm.passwordchecker;

import com.unirio.pm.interfaces.PasswordRule;
import com.unirio.pm.rules.MultipleRegex;
import com.unirio.pm.rules.RegexChecker;
import com.unirio.pm.rules.RegexFrequencyChecker;
import com.unirio.pm.rules.ScoreEvaluator;
import com.unirio.pm.rules.MultipleRules;

public class RunPasswordChecker {
	
	public static void main(String[] args) {
		
		String password = args[0];
		
		//PWC01
		int[] range01 = {16,25,35,45};
    	String[] result01 = {"very weak", "weak", "medium", "strong", "very strong"};
    	ScoreEvaluator evaluator01 = new ScoreEvaluator(range01, result01);
		PasswordChecker passwordChecker01 = new PasswordChecker(evaluator01);
		PasswordRule[] rules = {
				new RegexChecker("^.{0,4}$", 3),
			    new RegexChecker("^.{5,7}$", 6),
			    new RegexChecker("^.{8,16}$", 12),
			    new RegexChecker("^.{17,}$", 18)};
		passwordChecker01.addRule(new MultipleRules(rules));
		passwordChecker01.addRule(new RegexChecker("atLeastOneUpperCase",".*[A-Z].*",5));
		passwordChecker01.addRule(new RegexChecker("atLeastOneLowerCase",".*[a-z].*", 1));
		passwordChecker01.addRule(new RegexChecker("atLeastThreeDigits",".*[0-9].*[0-9].*[0-9].*", 5));
		passwordChecker01.addRule(new RegexChecker("containsOneSpecialCharacter", "\\w*\\W\\w*", 5));
		passwordChecker01.addRule(new RegexChecker("containsTwoOrMoreSpecialCharacters",".*\\W.*\\W.*", 10));
		passwordChecker01.addRule(new RegexChecker("atLeastOneUpperAndLowerCase","^(?=.*[A-Z].*)(?=.*[a-z].*).+$", 2));
		passwordChecker01.addRule(new RegexChecker("atLeastOneLetterAndNumber","^(?=.*[A-Za-z].*)(?=.*[0-9].*).+$", 2));
		passwordChecker01.addRule(new RegexChecker("atLeastOneSpecialCharacterAndWordCharacter","^(?=.*\\W.*)(?=.*\\w.*).+$", 2));
		int score01 = passwordChecker01.returnPasswordScore(password);
		String evaluation01 = passwordChecker01.returnPasswordEvaluation(score01);
	    System.out.println("Strength score for PWC01 is: " + score01);
	    System.out.println("Strength verdict for PWC01: " + evaluation01);
	    
	    //PWC02
	    int[] range02 = {20,40,60,80, 100};
    	String[] result02 = {"very weak", "weak", "medium", "strong", "very strong", "impossible"};
    	ScoreEvaluator evaluator02 = new ScoreEvaluator(range02, result02);
    	int size = password.length();
    	int score02 = size*4;
    	PasswordChecker passwordChecker02 = new PasswordChecker(evaluator02);
    	passwordChecker02.addRule(new RegexFrequencyChecker("[^A-Z]",2,"[A-Z]", true));
    	passwordChecker02.addRule(new RegexFrequencyChecker("[^a-z]",2,"[a-z]", true));
    	passwordChecker02.addRule(new RegexFrequencyChecker("[^0-9]",4,"[^0-9]", true));
    	passwordChecker02.addRule(new RegexFrequencyChecker("\\w",6,"\\w", true));
    	passwordChecker02.addRule(new RegexFrequencyChecker(".(\\W|\\d).",-2));
    	passwordChecker02.addRule(new RegexChecker("^(.*([A-Z][A-Z]|[a-z][a-z]).*)([A-Za-z]*).+$", size));
    	String [] regexes = {"(\\w\\w*)","^(?!.*[A-Z][A-Z]).*","^(?!.*[a-z][a-z]).*","(.*\\d.*)"};
    	passwordChecker02.addRule(new MultipleRegex(regexes, -size));
    	passwordChecker02.addRule(new RegexFrequencyChecker("((\\w)\\2+)+", 1));
    	passwordChecker02.addRule(new RegexFrequencyChecker("[A-Z][A-Z]", 2));
    	passwordChecker02.addRule(new RegexFrequencyChecker("[a-z][a-z]", 2));
    	passwordChecker02.addRule(new RegexFrequencyChecker("[0-9][0-9]", 2));
    	passwordChecker02.addRule(new RegexFrequencyChecker("(?:ab|bc|cd|de|ef|fg|gh|hi|ij|jk|kl|lm|mn|no|op|pq|qr|rs|st|tu|uv|vw|wx|xy|yz)", 3));
    	passwordChecker02.addRule(new RegexFrequencyChecker("(?:AB|BC|CD|DE|EF|FG|GH|HI|IJ|JK|KL|LM|MN|NO|OP|PQ|QR|RS|ST|TU|UV|VW|WX|XY|YZ)", 3));
    	passwordChecker02.addRule(new RegexFrequencyChecker("(?:12|23|34|45|56|67|78|89|90)", 3));
    	passwordChecker02.addRule(new RegexFrequencyChecker("(?:!@|@#|#$|$%|%^|^&)", 3));
    	score02 += passwordChecker02.returnPasswordScore(password);
		String evaluation02 = passwordChecker02.returnPasswordEvaluation(score02);
	    System.out.println("Strength score for PWC02 is: " + score02);
	    System.out.println("Strength verdict for PWC02: " + evaluation02);
	}
	

}
